@page
@using EasyAbp.FileManagement.Permissions
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using EasyAbp.FileManagement.Web.Pages.FileManagement.Files.File
@using EasyAbp.FileManagement.Localization
@model IndexModel
@inject IPageLayout PageLayout
@inject IHtmlLocalizer<FileManagementResource> L
@inject IAuthorizationService Authorization
@{
    PageLayout.Content.Title = L["File"].Value;
    PageLayout.Content.BreadCrumb.Add(L["Menu:File"].Value);
    PageLayout.Content.MenuItemName = "FileManagementFile";

    // Todo: should be full path
    var currentPath = Model.CurrentDirectory?.FileName;
}

@section scripts {
    <abp-script-bundle>
        <abp-script src="/Pages/FileManagement/Files/File/index.js" />
        <abp-script src="/libs/popper.js/umd/popper.min.js"/>
        <abp-script src="/libs/bootstrap-fileinput/js/fileinput.min.js"/>
        <abp-script src="/libs/bootstrap-fileinput/js/plugins/purify.min.js"/>
        <abp-script src="/libs/bootstrap-fileinput/js/plugins/sortable.min.js"/>
        <abp-script src="/libs/bootstrap-fileinput/themes/fa/theme.min.js"/>
    </abp-script-bundle>
}
@section styles {
    <abp-style-bundle>
        <abp-style src="/Pages/FileManagement/Files/File/index.css"/>
        <abp-style src="/libs/bootstrap-fileinput/css/fileinput.min.css"/>
    </abp-style-bundle>
}

@if (Model.ViewModel.FileContainerName == null)
{
    <abp-dynamic-form abp-model="ViewModel" data-ajaxForm="true" asp-page="Index">
        <abp-card>
            <abp-card-header>
                <abp-row>
                    <abp-column size-md="_6">
                        <abp-card-title>@L["File"]</abp-card-title>
                    </abp-column>
                </abp-row>
            </abp-card-header>
            <abp-card-body>
                <abp-form-content></abp-form-content>
            </abp-card-body>
            <abp-modal-footer>
                <abp-button id="search-button" button-type="Primary" text="Search"/>
            </abp-modal-footer>
        </abp-card>
    </abp-dynamic-form>
}
else
{
    <script>
        var fileContainerName = '@Model.ViewModel.FileContainerName';
        var ownerUserId = '@Model.ViewModel.OwnerUserId';
        var parentId = '@Model.ParentId';
    </script>
                                                       
    <abp-card>
        <abp-card-header>
            <abp-row>
                <abp-column size-md="_6">
                    <abp-card-title>@L["File"]: @currentPath</abp-card-title>
                </abp-column>
                <abp-column size-md="_6" class="text-right">
                    @if (await Authorization.IsGrantedAsync(FileManagementPermissions.File.Create))
                    { 
                        <abp-button id="CreateDirectoryButton"
                                    text="@L["CreateDirectory"].Value"
                                    icon="plus"
                                    button-type="Secondary" />
                        <abp-button id="UploadFileButton"
                                    text="@L["UploadFile"].Value"
                                    icon="plus"
                                    button-type="Primary" />
                    }
                </abp-column>
            </abp-row>
        </abp-card-header>
        <abp-card-body>
            <abp-table striped-rows="true" id="FileTable" class="nowrap">
                <thead>
                <tr>
                    <th>@L["Actions"]</th>
                    <th>@L["FileFileName"]</th>
                    <th>@L["FileByteSize"]</th>
                </tr>
                </thead>
            </abp-table>
        </abp-card-body>
    </abp-card>
}